package com.company.test16;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

/**
 * Created by Administrator on 2016.8.3.
 */
public class Test1606 extends JFrame{
    public Test1606(){
        MyPanel panel=new MyPanel();
        panel.addMouseListener(new MouseListener() {
            @Override
            public void mouseClicked(MouseEvent e) {
                panel.change();
            }

            @Override
            public void mousePressed(MouseEvent e) {

            }

            @Override
            public void mouseReleased(MouseEvent e) {

            }

            @Override
            public void mouseEntered(MouseEvent e) {

            }

            @Override
            public void mouseExited(MouseEvent e) {

            }
        });
        this.add(panel);
    }

    public static void main(String[] args){
        Test1606 frame=new Test1606();
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.setTitle("Welcome to JAVA");
        frame.setLocationRelativeTo(null);
        frame.setSize(300,300);
        frame.setVisible(true);
    }

    private class MyPanel extends JPanel{
        String message="Java is fun";

        private MyPanel(){

        }

        @Override
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);

            g.drawString(message,getWidth()/2,getHeight()/2);
        }

        public void change(){
            if (message.equals("Java is fun")){
                message="JAVA is powerful";
            }else {
                message="Java is fun";
            }
            repaint();
        }
    }
}
